package org.codeasy.ceutils.set;

import java.util.List;

import org.codeasy.ceutils.string.StringUtil;

public class ListUtil {

	/**
	 * 把LIST转为数组
	 * 
	 * @param list
	 * @return
	 */
	public static String[] list2Array(List<String> list) {
		return (String[])list.toArray(new String[list.size()]);
	}
	
	/**
	 * 判断str的indexOf List中的每个String,是否存在不为-1的
	 * @param str 如"ORACLE10g"
	 * @param keysList "ORACLE","MYSQL" 
	 * 以上例子会返回匹配上的字符串
	 * @return 
	 */
	public static String strContainKeyInList (String str, List<String> keysList) {
		if (keysList == null || str == null) {
			return null;
		}
		for ( String key : keysList) {
			if (str.indexOf(key) != -1) {
				return key;
			}
		}
		return null;
	}
	
	/**
	 * 把LIST里面的字符串根据指定符号拼成串
	 * 
	 * @param strList
	 * @param joinFlag
	 * @return
	 */
	public static String joinList2Str (List<String> strList, String joinFlag) {
		if (strList == null || joinFlag == null) {
			return null;
		}
		StringBuffer sb = new StringBuffer();
		for (String str : strList) {
			sb.append(str);
			sb.append(joinFlag);
		}
		
		return StringUtil.removeLastStr(sb.toString(), joinFlag.length());
	}
	
}
